package com.jiaotong.smart.smartjiaotong.controller.subregionconfigcontroller;

import com.jiaotong.smart.smartjiaotong.entity.ResponseEntity;
import com.jiaotong.smart.smartjiaotong.entity.subregionconfig.Subregion;
import com.jiaotong.smart.smartjiaotong.service.subregionconfigservice.serviceiml.SubRegionserviceiml;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

@RestController
@RequestMapping("/subregion")
public class SubRegionController {

    @Autowired
    SubRegionserviceiml subRegionserviceiml;

    @GetMapping("/number")
    public ResponseEntity getsubregionnumber(){
        long[] getnumber = subRegionserviceiml.getnumber();
        ResponseEntity responseEntity =
                new ResponseEntity(200,"return on/down number of subregion success",getnumber);
        return responseEntity;
    }

    //返回某个区域的所有子区
    @GetMapping("/subregions")
    public ResponseEntity getsubregions(@RequestParam("regionid") int regionid){
        List<Subregion> getallsubregionbyregionid = subRegionserviceiml.getallsubregionbyregionid(regionid);
        ResponseEntity responseEntity =
                new ResponseEntity(200,"all subregion of this region",getallsubregionbyregionid);
        return responseEntity;
    }


    @RequestMapping("/searchsubregion")
    public ResponseEntity getsubregions(@RequestParam("name") String name){
        System.out.println("name"+name);
        List<Subregion> getsubregionbyname = subRegionserviceiml.getsubregionbyname(name);
        System.out.println("查询结果"+getsubregionbyname);
        return new ResponseEntity(200,"list of subregion about name",getsubregionbyname);
    }

    @GetMapping("/getsearchcords")
    public ResponseEntity getsearchcords(){
        return new ResponseEntity(200,"all searchcords",subRegionserviceiml.getsearchrecords());
    }

    @GetMapping("/ni")
    public ResponseEntity test(@RequestParam("id") int id){
        return new ResponseEntity(200,"nihao","nihao"+id);
    }
}
